<template>
  <div id="orderuser">
    <el-row type="flex" align="middle"  justify="center" class="row-bg" style="height: 70px">
      <el-form :model="check" :rules="rules" :inline="true"  ref="check" status-icon class="demo-form-inline" label-position="left" size="small">
        <el-form-item label="商品名称" prop="goodName">
          <el-input v-model="check.goodName" placeholder="请输入商品名称"></el-input>
        </el-form-item>
        <el-form-item label="订单编号" prop="orderNum">
          <el-input v-model="check.orderNum" placeholder="请输入订单编号"></el-input>
        </el-form-item>
        <el-form-item label="订单状态" prop="orderState">
          <el-select v-model="check.orderState" clearable  placeholder="请选择" @change="queryOrders" @clear="queryOrders">
            <el-option
                key="1"
                label="待支付"
                value="1">
            </el-option>
            <el-option
                key="2"
                label="待发货"
                value="2">
            </el-option>
            <el-option
                key="3"
                label="已发货"
                value="3">
            </el-option>
            <el-option
                key="4"
                label="已完成"
                value="4">
            </el-option>
            <el-option
                key="5"
                label="售后处理中"
                value="5">
            </el-option>
            <el-option
                key="6"
                label="售后已完成"
                value="6">
            </el-option>
            <el-option
                key="7"
                label="已取消"
                value="7">
            </el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="queryOrders">查询</el-button>
          <el-button type="primary" @click="doReset('check')">重置</el-button>
          <el-button type="primary" @click="batchDelete">批量删除</el-button>
        </el-form-item>
      </el-form>
    </el-row>
    <el-row>
      <el-col :span="24">
        <div class="grid-content bg-purple-dark">
          <el-table
              :data="pageOrderData.list"
              height="80vh"
              border
              style="width: 100%"
              @selection-change="handleSelectionChange">
            <el-table-column
                type="selection"
                :selectable="selectEnable"
                disabled="true"
                width="30">
            </el-table-column>
            <el-table-column
                prop="id"
                v-if="false">
            </el-table-column>
            <el-table-column
                prop="comments"
                v-if="false">
            </el-table-column>
            <el-table-column
                label="序号"
                width="50">
              <template slot-scope="scope">
                {{scope.$index+1}}
              </template>
            </el-table-column>
            <el-table-column
                prop="orderNum"
                label="订单编号"
                width="80">
            </el-table-column>
            <el-table-column
                label="商品主图"
                width="115">
              <template slot-scope="scope">
                <el-avatar shape="square" :size="100" fit="fill" :src="scope.row.goodImg"></el-avatar>
              </template>
            </el-table-column>
            <el-table-column
                prop="goodName"
                label="商品名称"
                width="100">
            </el-table-column>
            <el-table-column
                prop="goodPrice"
                label="商品原价（元）"
                width="80">
            </el-table-column>
            <el-table-column
                prop="discount"
                label="优惠价格（元）"
                width="80">
            </el-table-column>
            <el-table-column
                prop="deductionAmount"
                label="积分抵扣金额（元）"
                width="80">
            </el-table-column>
            <el-table-column
                prop="buyNum"
                label="购买数量"
                width="80">
            </el-table-column>
            <el-table-column
                prop="actualPay"
                label="实际支付金额（元）"
                width="80">
            </el-table-column>
            <el-table-column
                label="创建时间"
                width="180">
              <template slot-scope="scope">
                <i class="el-icon-time"></i>
                <span style="margin-left: 10px">{{ scope.row.createTime}}</span>
              </template>
            </el-table-column>
            <el-table-column
                prop="orderState"
                label="订单状态"
                width="60">
              <template slot-scope="scope">
                <span v-if="scope.row.orderState === 1" style="color: #909399">待支付</span>
                <span v-if="scope.row.orderState === 2" style="color: #F56C6C">待发货</span>
                <span v-if="scope.row.orderState === 3" style="color: #67C23A">已发货</span>
                <span v-if="scope.row.orderState === 4" style="color: #67C23A">订单已完成</span>
                <span v-if="scope.row.orderState === 5" style="color: #E6A23C">售后处理中</span>
                <span v-if="scope.row.orderState === 6" style="color: #67C23A">售后已完成</span>
                <span v-if="scope.row.orderState === 7" style="color: #909399">已取消</span>
              </template>
            </el-table-column>
            <el-table-column
                label="操作">
              <template slot-scope="scope">
                <el-link type="primary" @click="queryDetails(scope.row)">详情</el-link>
                <el-link v-if="scope.row.orderState === 1 || scope.row.orderState === 7" type="danger" @click="deleteOrder(scope.row.id)" style="margin-left: 10px">删除</el-link>
                <el-link v-if="scope.row.orderState === 3" type="warning" @click="sign(scope.row)" style="margin-left: 10px">签收</el-link>
                <el-link v-if="scope.row.orderState === 1 || scope.row.orderState === 2" type="success" @click="orderUpdate(scope.row)" style="margin-left: 10px">修改</el-link>
                <el-link v-if="(scope.row.orderState === 4 || scope.row.orderState === 6) && scope.row.comments === 0" type="warning" @click="commentsAdd(scope.row)" style="margin-left: 10px">评价</el-link>
                <el-link v-if="scope.row.orderState === 4" type="danger" @click="orderAfterSales(scope.row)" style="margin-left: 10px">申请售后</el-link>
                <el-link v-if="scope.row.orderState === 5 || scope.row.orderState === 6" type="danger" @click="querySalesDetails(scope.row)" style="margin-left: 10px">售后详情</el-link>
                <el-link v-if="scope.row.orderState === 5" type="info" style="margin-left: 10px" @click="dealSales(scope.row)">取消售后</el-link>
              </template>
            </el-table-column>
          </el-table>
        </div>
      </el-col>
    </el-row>

    <!--分页部分-->
    <el-row type="flex" justify="center" class="el-row" style="margin-top: 30px">
      <el-col :span="24">
        <el-pagination
            background
            layout="prev,sizes, pager, next,total,jumper"
            :page-sizes="[1, 5, 10]"
            @next-click="nextPage"
            @prev-click="prevPage"
            @size-change="sizeChange"
            @current-change="currentPage"

            :page-size="pageOrderData.pageSize"
            :current-page="pageOrderData.pageNum"
            :total="pageOrderData.total"
            :page-count="pageOrderData.pages">
        </el-pagination>
      </el-col>
    </el-row>

    <!--详情部分-->
    <el-dialog :title="title" :visible.sync="orderIsVisiable" :modal="false">
      <div>
        <div style="float: left">
          <el-card :body-style="{ padding: '20px' }" >
          </el-card>
        </div>
      <el-form :model="rowData">
        <el-steps :active="rowData.active" finish-status="success" simple style="margin-top: 20px" v-if="rowData.orderState===1 || rowData.orderState===2 || rowData.orderState===3 || rowData.orderState===4">
          <el-step title="提交订单" ></el-step>
          <el-step title="付款成功" ></el-step>
          <el-step title="已经发货" ></el-step>
          <el-step title="确认收货" ></el-step>
        </el-steps>
        <el-steps :active="1" finish-status="success" simple style="margin-top: 20px" v-if="rowData.orderState===5">
          <el-step title="申请售后" ></el-step>
          <el-step title="售后完成" ></el-step>
        </el-steps>
        <el-steps :active="2" finish-status="success" simple style="margin-top: 20px" v-if="rowData.orderState===6">
          <el-step title="申请售后" ></el-step>
          <el-step title="售后完成" ></el-step>
        </el-steps>
        <el-form-item label="下单客户:" :label-width="formLabelWidth" style="margin-top: 40px">
          <el-input v-model="rowData.account" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="创建时间:" :label-width="formLabelWidth" style="margin-top: 40px">
          <el-input v-model="rowData.createTime" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="送货地址:" :label-width="formLabelWidth" style="margin-top: 40px">
          <el-input v-model="rowData.address" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="送货区域:" :label-width="formLabelWidth" style="margin-top: 40px">
          <el-input v-model="rowData.region" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <h1>订单编号 : {{rowData.orderNum}}</h1>
        <el-button @click="orderIsVisiable = false">取 消</el-button>
        <el-button @click="orderIsVisiable = false">确 定</el-button>
      </div>
      </div>
    </el-dialog>

    <!--售后详情部分-->
    <el-dialog :title="title" :visible.sync="servicesIsVisiable" :modal="false">
      <el-form :model="salesData">
        <el-steps :active="1" finish-status="success" simple style="margin-top: 20px" v-if="salesData.status===1">
          <el-step title="处理售后中" ></el-step>
          <el-step title="售后结果" ></el-step>
        </el-steps>
        <el-steps :active="2" finish-status="success" simple style="margin-top: 20px" v-if="salesData.status===2">
          <el-step title="处理售后中" ></el-step>
          <el-step title="售后通过" />
          <i style="margin-left: 20px;color: #67C23A">{{salesData.salesTime}}</i>
        </el-steps>
        <el-steps :active="2" finish-status="success" simple style="margin-top: 20px" v-if="salesData.status===3">
          <el-step title="处理售后中" ></el-step>
          <el-step title="售后退回" />

        </el-steps>
        <el-descriptions v-if="salesData.status!=1" style="margin-top: 30px;margin-left: 50px">
          <el-descriptions-item label="申请用户">{{ salesData.userAccount }}</el-descriptions-item>
          <el-descriptions-item label="售后人员">{{ salesData.account }}</el-descriptions-item>
          <el-descriptions-item label="备注">
            <el-tag size="small" v-if="salesData.status===2">售后通过</el-tag>
            <el-tag size="small" v-if="salesData.status===3" style="color: #F56C6C">售后退回</el-tag>
          </el-descriptions-item>
          <el-descriptions-item label="申请原因">
            <span v-if="salesData.information === 1" style="color: #F56C6C">其他</span>
            <span v-if="salesData.information === 2" style="color: #F56C6C">收到商品破损</span>
            <span v-if="salesData.information === 3" style="color: #F56C6C">商品错发、漏发</span>
            <span v-if="salesData.information === 4" style="color: #F56C6C">商品需要维修</span>
            <span v-if="salesData.information === 5" style="color: #F56C6C">发票问题</span>
            <span v-if="salesData.information === 6" style="color: #F56C6C">收到商品与描述不符</span>
            <span v-if="salesData.information === 7" style="color: #F56C6C">商品质量问题</span>
            <span v-if="salesData.information === 8" style="color: #F56C6C">未按约定时间发货</span>
          </el-descriptions-item>
          <el-descriptions-item label="处理原因">
            <span v-if="salesData.news === 1" style="color: #F56C6C">符合退换条件</span>
            <span v-if="salesData.news === 2" style="color: #F56C6C">商品或销售行为不存在过错</span>
            <span v-if="salesData.news === 3" style="color: #F56C6C">不在保修条款内，并不符合保修政策</span>
            <span v-if="salesData.news === 4" style="color: #F56C6C">商品已被拆包使用</span>
            <span v-if="salesData.news === 5" style="color: #F56C6C">超过退换货时间</span>
          </el-descriptions-item>

          <el-descriptions-item label="订单编码">{{ salesData.orderNum }}</el-descriptions-item>
        </el-descriptions>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="servicesIsVisiable = false">取 消</el-button>
        <el-button @click="servicesIsVisiable = false">确 定</el-button>
      </div>
    </el-dialog>

    <!--申请售后-->
    <el-dialog :title="titleAfter" :visible.sync="afterSalesIsVisiable" :modal="false">
      <el-form :model="afterSalesData">
        <el-form-item label="申请原因" prop="information" :label-width="formLabelWidth" style="margin-top: 20px" >
          <el-select v-model="afterSalesData.information" clearable  placeholder="请选择">
            <el-option
                key="1"
                label="其他"
                value="1">
            </el-option>
            <el-option
                key="2"
                label="收到商品破损"
                value="2">
            </el-option>
            <el-option
                key="3"
                label="商品错发、漏发"
                value="3">
            </el-option>
            <el-option
                key="4"
                label="商品需要维修"
                value="4">
            </el-option>
            <el-option
                key="5"
                label="发票问题"
                value="5">
            </el-option>
            <el-option
                key="6"
                label="未收到商品,取消订单"
                value="6">
            </el-option>
            <el-option
                key="7"
                label="商品质量问题"
                value="7">
            </el-option>
          </el-select>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <h1>用户账号 : {{this.orders.account}}</h1>
        <el-button type="info" plain @click="afterSalesIsVisiable=false">取 消</el-button>
        <el-button type="success" plain @click="applyAfterSales">确 定</el-button>
      </div>
    </el-dialog>

    <!--修改订单-->
    <el-dialog :title="titleUpdate" :visible.sync="updateOrderIsVisiable" :modal="false">
      <el-form :model="updateOrderData">
        <el-form-item label="修改送货地址" prop="address" :label-width="formLabelWidth" style="margin-top: 20px" >
          <el-input v-model="updateOrderData.address" autocomplete="off"></el-input>
        </el-form-item>
        <el-form-item label="修改送货区域" prop="address" :label-width="formLabelWidth" style="margin-top: 20px" >
          <el-input v-model="updateOrderData.region" autocomplete="off"></el-input>
        </el-form-item>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <h1>订单编号 : {{updateOrderData.orderNum}}</h1>
        <el-button type="info" plain @click="updateOrderIsVisiable = false">取 消</el-button>
        <el-button type="success" plain @click="updateAddress">确 定</el-button>
      </div>
    </el-dialog>

    <!--评价部分-->
    <el-dialog :title="titleComments" :visible.sync="commentsIsVisiable" :modal="false">
      <el-form :model="commentsData">
        <el-form-item label="商品编码" prop="address" :label-width="formLabelWidth" style="margin-top: 20px" >
          <el-input v-model="commentsData.goodCode" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="顾客账号" prop="account" :label-width="formLabelWidth" style="margin-top: 20px" >
          <el-input v-model="commentsData.account" autocomplete="off" :disabled="true"></el-input>
        </el-form-item>
        <el-form-item label="评论内容" prop="comments" :label-width="formLabelWidth" style="margin-top: 20px" >
          <el-input v-model="commentsData.comments" autocomplete="off"></el-input>
        </el-form-item>
<!--        <el-form-item label="商品得分" prop="score" :label-width="formLabelWidth" style="margin-top: 20px" >-->
          <div class="block">
            <span class="demonstration">商品得分</span>
          <el-rate v-model="commentsData.score" style="margin-top: 20px"></el-rate>
          </div>
<!--        </el-form-item>-->
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="info" plain @click="commentsIsVisiable = false">取 消</el-button>
        <el-button type="success" plain @click="commentsInsert">确 定</el-button>
      </div>
    </el-dialog>

  </div>
</template>

<script>
import comments from "@/components/commoditymanager/comments.vue";

export default {
  name: "orderuser",
  computed: {
    comments() {
      return comments
    }
  },
  data(){
    return{
      orders:{
        id:'',
        buyNum:'',
        actualPay:'',
        createTime:'',
        orderState:'',
        account:'',
        orderId:'',
        sendTime:'',
        orderNum:'',
        comments:''
      },
      //售后数据
      sales:{
        id:'',
        orderId:'',
        endTime:'',
        status:''
      },
      //分页相关
      pageOrderData:{
        list:'',
        total:'',
        pageNum:1,
        pageSize:5,
        pages:''
      },
      //查询相关
      check:{
        goodName:'',
        orderNum:'',
        orderState:'',
        account:''
      },
      //详情页面
      rowData:{
        account:'',
        createTime:'',
        active:'',
        orderState:'',
        orderNum:'',
        comments:'',
        region:'',
        address:''
      },
      //售后详情页面
      salesData:{
        account:'',
        serviceId:'',
        salesTime:'',
        status:'',
        orderNum:'',
        information:'',
        userAccount:'',
        news:''
      },
      //售后跳窗页面
      afterSalesData:{
        orderState:'',
        userAccount:'',
        serviceId:'',
        information:'',
        orderNum:''
      },
      //订单修改页面
      updateOrderData:{
        address:'',
        orderId:'',
        userAccount:'',
        region:'',
        orderNum:'',
        orderID:''
      },
      //评论页面
      commentsData:{
        goodCode:'',
        goodsCode:'',
        customerId:'',
        account:'',
        comments:'',
        score:'',
        isTop:'',
        isVisiable:''
      },
      //订单详情弹窗是否可视
      orderIsVisiable:false,
      afterSalesIsVisiable:false,
      updateOrderIsVisiable:false,
      commentsIsVisiable:false,
      servicesIsVisiable:false,
      formLabelWidth: '120px',
      title:'订单详情',
      titleAfter:'申请售后',
      titleUpdate:'修改送货地址',
      titleComments:'新增评论',
      rules:{
        goodName: [
          { message: '商品名称', trigger: 'blur' }
        ],
        orderNum: [
          {  message: '订单编号', trigger: 'blur' }
        ],
        orderState: [
          {message: '请选择订单状态', trigger: 'change' }
        ]
      },
    }
  },
  methods:{
    selectEnable(row, rowIndex){
      if (row.orderState != 7) {
        return false;
      }else {
        return true;
      }
    },
    queryOrders(){
      let jwt=localStorage.getItem("jwt");
      this.orders.account = sessionStorage.getItem("account");
      var url = '/api/orders/orderList?goodName=' + this.check.goodName + '&orderNum=' + this.check.orderNum + '&orderState=' + this.check.orderState +'&account=' + this.orders.account + '&pageNum=' + this.pageOrderData.pageNum + '&pageSize=' + this.pageOrderData.pageSize;
      this.$axios.get(url,{headers:{"jwt":jwt}})
          .then(response =>{
            // console.log(response.data);
            if(response.data.code==200){
              this.pageOrderData=response.data.data;
              // console.log(this.pageOrderData);
            }else {
              this.pageOrderData.list=null;
              this.pageOrderData.pages=0;
              this.pageOrderData.total=0;
              this.pageOrderData.pageNum=1;
              this.pageOrderData.pageSize=5;
              this.$message.warning(response.data.msg);
            }
          });
    },
    handleSelectionChange(val){
      this.multipleSelection=val;
    },
    nextPage(pageNum){
      this.pageOrderData.pageNum=pageNum;
    },
    prevPage(pageNum){
      this.pageOrderData.pageNum=pageNum;
    },
    currentPage(pageNum){
      this.pageOrderData.pageNum=pageNum;
      this.queryOrders();
    },
    sizeChange(size){
      this.pageOrderData.pageSize=size;
      if (this.pageOrderData.pageNum!=1){
        this.pageOrderData.pageNum=1;
      }else{
        this.queryOrders();
      }
    },
    doReset(check){
      this.$refs[check].resetFields();
      this.pageOrderData.pageSize=5;
      this.pageOrderData.pageNum=1;
      this.queryOrders();
    },
    //打开售后
    orderAfterSales(row){
        this.afterSalesIsVisiable=true;
        this.sales.orderId=row.id;
        this.sales.status=1;
        this.afterSalesData.orderNum=row.orderNum;
        console.log(this.afterSalesData);
    },
    //申请售后
    applyAfterSales(){
      let jwt=localStorage.getItem("jwt");
      this.$axios.post('/api/services/servicesAdd',this.sales,{headers:{"jwt":jwt}}).then(response=>{
        if(response.data.code==200){
          this.$axios.get('/api/services/queryServicesByOrderId?orderId='+this.sales.orderId,{headers:{"jwt":jwt}}).then(respon=>{
            if(respon.data.code==200){
              this.sales=respon.data.data;
              this.afterSalesData.serviceId=this.sales.id;
              this.afterSalesData.userAccount=this.orders.account;
              this.afterSalesData.orderState=5;
                this.$axios.post('/api/services/serviceDealAdd',this.afterSalesData,{headers:{"jwt":jwt}}).then(resp=>{
                  this.$axios.post('/api/orders/orderUpdateOrderState',this.afterSalesData,{headers:{"jwt":jwt}}).then(res=>{
                    if(res.data.code==200){
                      this.$message.success("已成功申请售后");
                      this.afterSalesIsVisiable=false;
                      this.queryOrders();
                    }else{
                      this.$message.error("操作失败,请重试");
                    }
                  })
                })
            }
          })
        }else{
          this.$message.error("出了点小小的错误,请重试");
        }
      });
      this.queryOrders();
    },
    //售后详情界面
    querySalesDetails(row){
      let jwt=localStorage.getItem("jwt");
      this.servicesIsVisiable=true;
      this.$axios.get('api/services/queryServicesByOrderId?orderId='+row.id,{headers:{'jwt':jwt}}).then(response=>{
          this.salesData.status=response.data.data.status;
          this.salesData.serviceId=response.data.data.id;
          this.$axios.get('api/services/servicesDetails?serviceId='+this.salesData.serviceId,{headers:{'jwt':jwt}}).then(response =>{
            console.log(response.data.data);
            if(response.data.code==200){
              this.salesData.orderNum=row.orderNum;
              this.salesData.account=response.data.data.account;
              this.salesData.salesTime=response.data.data.salesTime;
              this.salesData.news=response.data.data.news;
              this.salesData.information=response.data.data.information;
              this.salesData.userAccount=response.data.data.userAccount;
            }else if(response.data.data==406) {
              this.$message.warning(response.data.msg);
              this.$router.push("/login")
            }
          })
        })
    },
    //签收
    sign(row){
      this.orders.orderNum=row.orderNum;
      this.orders.orderState=4;
      let jwt=localStorage.getItem("jwt");
      this.$axios.post('api/orders/orderUpdateOrderState',this.orders,{headers:{"jwt":jwt}}).then(response=>{
          if(response.data.code==200){
            this.queryOrders();
            this.$message.success("已成功签收");
          }else{
            this.$message.error("操作失败,请重试");
          }
      })
      this.queryOrders();
    },
    //打开修改订单界面
    orderUpdate(row){
      let jwt=localStorage.getItem("jwt");
      this.updateOrderIsVisiable=true;
      this.updateOrderData.orderId=row.id;
      this.updateOrderData.orderID=row.id;
      this.updateOrderData.orderNum=row.orderNum;
      this.$axios.get('api/address/queryAddressByOrderId?id='+row.id,{headers:{"jwt":jwt}}).then(response=>{
          this.updateOrderData.address=response.data.data.address;
          this.updateOrderData.region=response.data.data.region;
      })
    },
    //修改订单
    updateAddress(){
      let jwt=localStorage.getItem("jwt");
      console.log(this.updateOrderData);
      this.$axios.post('api/address/updateAddress',this.updateOrderData,{headers:{"jwt":jwt}}).then(response=>{
        if(response.data.code==200){
          this.$message.success("已成功修改收货地址");
        }else{
          this.$message.error("操作失败,请重试");
        }
      })
      this.updateOrderIsVisiable=false;
    },
    //打开新增评论页面
    commentsAdd(row){
        this.commentsIsVisiable=true;
        this.commentsData.account=row.account;
        this.commentsData.goodCode=row.goodCode;
        this.commentsData.goodsCode=row.goodCode;
        this.commentsData.isTop=1;
        this.commentsData.isVisiable=1;
        this.orders.orderNum=row.orderNum;
        let jwt=localStorage.getItem("jwt");
        this.$axios.get('api/customer/queryIdByAccount?account='+this.commentsData.account,{headers:{"jwt":jwt}}).then(response=>{
            this.commentsData.customerId=response.data.data;
        });
    },
    //评论新增
    commentsInsert(){
      let jwt=localStorage.getItem("jwt");
      this.orders.comments=1;
      this.$axios.post('api/comments/commentsAdd',this.commentsData,{headers:{"jwt":jwt}}).then(response=>{
        if(response.data.code==200){
          this.$axios.post('api/orders/orderUpdateComments',this.orders,{headers:{"jwt":jwt}}).then(respon=>{
            if(response.data.code==200){
              this.queryOrders();
              this.$message.success("已成功新增评论");
            }
          })
        }else{
          this.$message.error("操作失败,请重试");
        }
      });
      this.queryOrders();
      this.commentsIsVisiable=false;
    },
    //取消售后
    dealSales(row){
      let jwt=localStorage.getItem("jwt");
      this.orders.orderNum=row.orderNum;
      this.sales.orderId=row.id;
      this.orders.orderState=4;
      this.sales.status=4;
      // console.log(this.orders);
      // console.log(this.sales);
      this.$confirm('是否取消售后?','提示',{
        confirmButtonText:'确定',
        cancelButtonClass:'取消',
        type:'warning'
      }).then(() =>{
        //确定
        this.$axios.post('api/orders/orderUpdateOrderState',this.orders,{headers:{"jwt":jwt}}).then(response=>{
          if(response.data.code==200){
            this.$axios.get('api/services/queryServicesByOrderId?orderId='+this.sales.orderId,{headers:{"jwt":jwt}}).then(respon=>{
              this.sales.id=respon.data.data.id;
              this.$axios.get('api/services/servicesDelete?id='+this.sales.id,{headers:{"jwt":jwt}}).then(resp=>{
                if(resp.data.code==200){
                  this.$axios.get('api/services/userServicesDelete?serviceId='+this.sales.id,{headers:{"jwt":jwt}}).then(res=>{
                    this.$message.success("已成功取消售后");
                  })
                }
              })
            })
          }else{
            this.$message.error("操作失败,请重试");
          };
          this.queryOrders();
        })
      }).catch(() => {
            this.$message({
              type: 'info',
              message: '取消售后未成功'
            });
          });
    },
    queryDetails(row){
      let jwt=localStorage.getItem("jwt");
      this.rowData.orderState=row.orderState;
      if(row.orderState == 7){
        this.$alert('该订单已取消', '订单详情', {
          confirmButtonText: '确定',
          callback: action => {
          }
        })
      }else{
        this.orderIsVisiable=true;
        this.rowData.active=row.orderState;
        this.rowData.account=row.account;
        this.rowData.createTime=row.createTime;
        this.rowData.orderNum=row.orderNum;
        this.$axios.get('api/address/queryAddressByOrderId?id='+row.id,{headers:{"jwt":jwt}}).then(response=>{
          if(response.data.code==200) {
            this.rowData.address = response.data.data.address;
            this.rowData.region = response.data.data.region;
            // console.log(this.rowData);
          }else{
            this.$message.error("WDNMD,我没查出来");
          }
        })
        // this.$axios.get('api/orders/orderDetails?orderId='+row.id,{headers:{'jwt':jwt}}).then(response =>{
        //   console.log(response.data.data);
        //   if(response.data.data.account != null && response.data.data.sendTime != null){
        //     this.rowData.orderId=row.id;
        //     this.rowData.orderNum=row.orderNum;
        //     this.rowData.account=response.data.data.account;
        //     this.rowData.sendTime=response.data.data.sendTime;
        //   }
        // })
      }
    },
    deleteOrder(id){
      let jwt=localStorage.getItem("jwt");
      this.$axios.get('api/orders/orderDelete?id='+id,{headers:{"jwt":jwt}}).then(response => {
        if(response.data.code==200){
          this.$message.success("已成功删除");
          this.queryOrders();
        }else{
          this.$message.error("操作失败,请重试");
        }
      });
    },
    batchDelete(){
      this.$confirm('是否删除?','提示',{
        confirmButtonText:'确定',
        cancelButtonClass:'取消',
        type:'warning'
      }).then(() =>{
        //确定
        let selectval = this.multipleSelection;
        let ids = [];
        selectval.forEach(e => {
          ids.push(e.id);
        });
        if(ids.length!=0){
          // console.log(ids);
          let jwt = localStorage.getItem("jwt");
          this.$axios.post('api/orders/batchDelete',ids,{headers:{'jwt':jwt}
          }).then(response =>{
            if(response.data.code == 200){
              this.$message({
                type: 'success',
                message: '删除成功!'
              });
              this.doReset('check');
            }else {
              this.$message({
                type: 'error',
                message: '删除失败!'
              });
            }
          })
        }
      })
          .catch(() => {
            this.$message({
              type: 'info',
              message: '已取消删除'
            });
          });
    },
  },
  created:function () {
    this.queryOrders();
  }
}
</script>

<style scoped>

</style>